package com.myk.game.gobangchess.signs;

import com.myk.game.gobangchess.Sign;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;

/**
 * 背景标记，方便给一整块矩形设置背景标记
 */
public class GroundSign extends Sign {

    private final int start;
    private final int end;
    private final String bgColor; //背景颜色
    private final String edColor; //边框颜色 （边框是针对一整个整体的）
    private final float size; //边框粗细比例
    private final int bgStyle; //背景样式 0：实色 （网格线，栅格线等等）
    private final int edStyle; //边线样式 0:实线， 1:虚线

    public GroundSign(int index, String bgColor, String edColor, float size) {
        this.start = index;
        this.end = index;
        this.bgColor = bgColor;
        this.edColor = edColor;
        this.size = size;
        this.bgStyle = 0;
        this.edStyle = 0;
    }

    public GroundSign(int start, int end, String bgColor, String edColor, float size) {
        this.start = start;
        this.end = end;
        this.bgColor = bgColor;
        this.edColor = edColor;
        this.size = size;
        this.bgStyle = 0;
        this.edStyle = 0;
    }

    public GroundSign(int index, String bgColor, String edColor, float size, int bgStyle, int edStyle) {
        this.start = index;
        this.end = index;
        this.bgColor = bgColor;
        this.edColor = edColor;
        this.size = size;
        this.bgStyle = bgStyle;
        this.edStyle = edStyle;
    }

    public GroundSign(int start, int end, String bgColor, String edColor, float size, int bgStyle, int edStyle) {
        this.start = start;
        this.end = end;
        this.bgColor = bgColor;
        this.edColor = edColor;
        this.size = size;
        this.bgStyle = bgStyle;
        this.edStyle = edStyle;
    }

    @Override
    public String getSignInfo() {
        return type + "," + start + "," + end + "," + bgColor + "," + edColor + "," + size + "," + bgStyle + "," + edStyle;
    }

    public void serialize(DataOutputStream dos) throws IOException {
        dos.writeInt(this.start);
        dos.writeInt(this.end);
        dos.writeUTF(this.bgColor);
        dos.writeUTF(this.edColor);
        dos.writeFloat(this.size);
        dos.writeInt(this.bgStyle);
        dos.writeInt(this.edStyle);
    }

    public GroundSign(DataInputStream dis) throws IOException {
        this.start = dis.readInt();
        this.end = dis.readInt();
        this.bgColor = dis.readUTF();
        this.edColor = dis.readUTF();
        this.size = dis.readFloat();
        this.bgStyle = dis.readInt();
        this.edStyle = dis.readInt();
    }

}
